import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface AppState {
  isLoading: boolean;
  isOnline: boolean;
  theme: 'light' | 'dark' | 'system';
  language: string;
  notifications: boolean;
}

const initialState: AppState = {
  isLoading: false,
  isOnline: true,
  theme: 'system',
  language: 'zh-CN',
  notifications: true,
};

const appSlice = createSlice({
  name: 'app',
  initialState,
  reducers: {
    setLoading: (state, action: PayloadAction<boolean>) => {
      state.isLoading = action.payload;
    },
    setOnlineStatus: (state, action: PayloadAction<boolean>) => {
      state.isOnline = action.payload;
    },
    setTheme: (state, action: PayloadAction<'light' | 'dark' | 'system'>) => {
      state.theme = action.payload;
    },
    setLanguage: (state, action: PayloadAction<string>) => {
      state.language = action.payload;
    },
    setNotifications: (state, action: PayloadAction<boolean>) => {
      state.notifications = action.payload;
    },
  },
});

export const { 
  setLoading, 
  setOnlineStatus, 
  setTheme, 
  setLanguage, 
  setNotifications 
} = appSlice.actions;

export default appSlice.reducer; 